package com.leonwoodstudio.eventdetectionclient.utils;

import android.graphics.Bitmap;
import android.os.Handler;
import android.widget.ImageView;

import com.leonwoodstudio.eventdetectionclient.EventHistoryListItem;
import com.leonwoodstudio.eventdetectionclient.MainActivity;
import com.leonwoodstudio.eventdetectionclient.eventmessage.ParsedEventMessageToSave;

/**
 * Created by win7 on 2017/4/23.
 */
public class CallbackImpl implements AsyncImageLoader.ImageCallback {
    private ImageView imageView ;
    private Handler handler;
    private ParsedEventMessageToSave parsed;

    public CallbackImpl(ImageView imageView, Handler handler, ParsedEventMessageToSave parsed) {
        super();
        this.imageView = imageView;
        this.handler = handler;
        this.parsed = parsed;
    }
    public void SetupNewParsed(ParsedEventMessageToSave parsed) {
        this.parsed = parsed;
    }
    @Override
    public void imageLoaded(Bitmap imageBitmap, ParsedEventMessageToSave parsed) {
        if (imageBitmap == null) {
            return;
        }
        if (parsed == this.parsed) {
            imageView.setImageBitmap(imageBitmap);
        }
        handler.obtainMessage(MainActivity.MSG_DOWNLOAD_PIC_DONE, parsed).sendToTarget();
    }
}
